﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using MySql.Data.MySqlClient;
using ConnectToDatabase.Model;

namespace ConnectToDatabase
{
    public class SetID:MarshalByRefObject
    {
       private SelectDB selectDB = new SelectDB();
       
        public String GenerateMaLoaiSP()
        {
            List<String> listMaLoaiSP = selectDB.SelectMaLoaiSP();
            string generatedMaLoaiSP;
            do
            {
                generatedMaLoaiSP = "";

                var chars = "FGDF8G7S5D7FWHJRTGEWO8652958645869SG6F9D8G75XC7V46X436D3F649JGTGE46DF7HJ3H52GHMBVUHJXVBSDIY";
                var random = new Random();
                var result = new String(
                    Enumerable.Repeat(chars, 3)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaLoaiSP += "LSP" + result;
            } while (listMaLoaiSP.Contains(generatedMaLoaiSP));
            return generatedMaLoaiSP;
        }

        public String GenerateMaNhaPP()
        {
            List<String> listMaNhaPP = selectDB.SelectMaNhaPP();
            string generatedMaNhaPP;
            do
            {
                generatedMaNhaPP = "";

                var chars = "JRT6F9D8G75XC7V46X436D3F64FWHMBVUGEWO865297HJ3H52GHFGDF8G7S5D795864586JGTGE46D9SGHJXVBSDIYF";
                var random = new Random();
                var result = new String(
                    Enumerable.Repeat(chars, 3)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaNhaPP += "NPP" + result;
            } while (listMaNhaPP.Contains(generatedMaNhaPP));
            return generatedMaNhaPP;
        }

        public String GenerateMaDauSP()
        {
            List<String> listMaDauSP = selectDB.SelectMaDauSP();
            string generatedMaDauSP;
            do
            {
                generatedMaDauSP = "";

                var chars = "F649DF8G7FJGTGE4FGWHJD8G75XC7V46X436DGEWO86HJ3H52GHMB96DF7869SG6DIYV295864U3RTHJXVBSS5D7F55";
                var random = new Random();
                var result = new String(
                    Enumerable.Repeat(chars, 3)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaDauSP += "DSP" + result;
            } while (listMaDauSP.Contains(generatedMaDauSP));
            return generatedMaDauSP;
        }

        public String GenerateMaKhuyenMai()
        {
            List<String> listMaKhuyenMai = selectDB.SelectMaKhuyenMai();
            string generatedMaKhuyenMai;
            do
            {
                generatedMaKhuyenMai = "";

                var chars = "SS5DF7869SG8G7FJGO86HJ3H52GHMBTGE4FGWHJD8G75F649DF36DGEW7F596THJXVBXC7V46X46DIYV295864U3RD5";
                var random = new Random();
                var result = new String(
                    Enumerable.Repeat(chars, 4)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaKhuyenMai += "KM" + result;
            } while (listMaKhuyenMai.Contains(generatedMaKhuyenMai));
            return generatedMaKhuyenMai;
        }

        public String GenerateMaPhieuTra()
        {
            List<String> listMaPhieuTra = selectDB.SelectMaPhieuTra();
            string generatedMaPhieuTra;
            do
            {
                generatedMaPhieuTra = "";

                var chars = "SS5DF78696XC7V298G75FE4FGW5866G49DF3696THJXVBSG8G7FJGO85GEHJV46X46DIY3H4U3RD52GHMBTW7F5HJDD";
                var random = new Random();
                var result = new String(
                    Enumerable.Repeat(chars, 4)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaPhieuTra += "PT" + result;
            } while (listMaPhieuTra.Contains(generatedMaPhieuTra));
            return generatedMaPhieuTra;
        }

        public String GenerateMaSanPham()
        {
            List<String> listMaSanPham = selectDB.SelectMaSanPham();
            string generatedMaSanPham;
            do
            {
                generatedMaSanPham = "";

                var chars = "FDS5DF785HJDC7V298696XJGO85GEHJV6G49DF3696THJXVB46X46DIY3H4U3RD52S86SG8G7GHMBTW7FG75FE4FGW5";
                var random = new Random();
                var result = new String(
                    Enumerable.Repeat(chars, 4)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaSanPham += "SP" + result;
            } while (listMaSanPham.Contains(generatedMaSanPham));
            return generatedMaSanPham;
        }

        public String GenerateMaLoaiNV()
        {
            List<String> listMaLoaiNV = selectDB.SelectMaLoaiNV();
            string generatedMaLoaiNV;
            do
            {
                generatedMaLoaiNV = "";

                var chars = "THJXVTW7FG754U3RD52S86SG8G7GF696XJGO85GEHJV6G49DF3696E4FGWB46X46DIY3HHMBFDS5DF785HJDC7V2985";
                var random = new Random();
                var result = new String(
                    Enumerable.Repeat(chars, 3)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaLoaiNV += "LNV" + result;
            } while (listMaLoaiNV.Contains(generatedMaLoaiNV));
            return generatedMaLoaiNV;
        }

        public String GenerateMaNV()
        {
            List<String> listMaNV = selectDB.SelectMaNV();
            string generatedMaNV;
            do
            {
                generatedMaNV = "";

                var chars = "V2G7GF696XJGO8546X46DITHJXVTW7FG754UGEHJV6G49DF3696E4FGWB3RD52S86SG8Y3HHMBFDS5DF785HJDC7985";
                var random = new Random();
                var result = new String(
                    Enumerable.Repeat(chars, 4)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaNV += "NV" + result;
            } while (listMaNV.Contains(generatedMaNV));
            return generatedMaNV;
        }

        public String GenerateMaDVBaoHanh()
        {
            List<String> listMaDVBaoHanh = selectDB.SelectMaDVBaoHanh();
            string generatedMaDVBaoHanh;
            do
            {
                generatedMaDVBaoHanh = "";

                var chars = "IG8Y3HGF696XJGO8546X46DS8HMBFDS5DF78THJXVTWB3RD52V2G76S5HJDC77FG754UGEHJV6G49DF3696E4FGW985";
                var random = new Random();
                var result = new String(
                    Enumerable.Repeat(chars, 4)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaDVBaoHanh += "BH" + result;
            } while (listMaDVBaoHanh.Contains(generatedMaDVBaoHanh));
            return generatedMaDVBaoHanh;
        }

        public String GenerateMaNhomSP()
        {
            List<String> listMaNhomSP = selectDB.SelectMaNhomSP();
            string generatedMaNhomSP;
            do
            {
                generatedMaNhomSP = "";

                var chars = "6X436DGEWO86YV29F649DF8G7FJGTGE4HJ3H52GHMB958S565D7F54U3RTHJXVB6DF7869SG6DIFGWHJD8G75XC7V4S";
                var random = new Random();
                var result = new String(
                    Enumerable.Repeat(chars, 3)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaNhomSP += "NSP" + result;
            } while (listMaNhomSP.Contains(generatedMaNhomSP));
            return generatedMaNhomSP;
        }

        public String GenerateMaPhieuNhap()
        {
            List<String> listMaPhieuNhap = selectDB.SelectMaPhieuNhap();
            string generatedMaPhieuNhap;
            do
            {
                generatedMaPhieuNhap = "";

                var chars = "6DF436DGEWO86YV29F649D7869SG6DIFGWHJ6XF8G95VBD8G75XC7VHJ3H52GH47FJ8S565D7F54U3RTHJXGTGE4MBS";
                var random = new Random();
                var result = new String(
                    Enumerable.Repeat(chars, 4)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaPhieuNhap += "PN" + result;
            } while (listMaPhieuNhap.Contains(generatedMaPhieuNhap));
            return generatedMaPhieuNhap;
        }

        public String GenerateMaHoaDon()
        {
            List<String> listMaHoaDon = selectDB.SelectMaHoaDon();
            string generatedMaHoaDon;
            do
            {
                generatedMaHoaDon = "";

                var chars = "524MBSS565649D786GEWO86YGH47FJ8JSG6DIFGW69D7F54U3RTHJXGTGEV29FF436DD6XF8G95VBD8G75XC7VHJ3HH";
                var random = new Random();
                var result = new String(
                    Enumerable.Repeat(chars, 4)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaHoaDon += "HD" + result;
            } while (listMaHoaDon.Contains(generatedMaHoaDon));
            return generatedMaHoaDon;
        }

        public String GenerateMaDangNhap()
        {
            List<String> listMaDangNhap = selectDB.SelectMaHoaDon();
            string generatedMaDangNhap;
            do
            {
                generatedMaDangNhap = "";

                var chars = "7FJ8JSG6DIFGW69D786GEWO8JXGTGEV29FF436DD6XF8G95V524MBSS566YGH4BD8G75XC7VHJ3H7F54U3RTH5649DH";
                var random = new Random();
                var result = new String(
                    Enumerable.Repeat(chars, 4)
                              .Select(s => s[random.Next(s.Length)])
                              .ToArray());
                generatedMaDangNhap += "DN" + result;
            } while (listMaDangNhap.Contains(generatedMaDangNhap));
            return generatedMaDangNhap;
        }

        public NhanVien GenerateXYZ()
        {
            NhanVien text = new NhanVien();
            return text;
        }

        public int Test() { return 0; }



    }
}
